package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Order;
import com.itheima.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.Date;

@Mapper
public interface OrderMapper {
    /**
     * 根据条件查询预约列表
     * @param queryString
     * @return
     */
    Page<OrderVO> findPage(String queryString);

    /**
     * 修改预约状态
     * @param order
     */
    @Update("update t_order set orderStatus = #{orderStatus} where id = #{id} ")
    void update(Order order);

    /**
     * 今日预约数
     * @param now
     * @return
     */
    @Select("select count(*) from t_order where orderDate = #{now}")
    Integer findTodayOrderNumber(LocalDate now);


    /**
     * 今日到诊数
     * @param now
     * @return
     */
    @Select("select count(*) from t_order where orderDate = #{now} and orderStatus = #{orderstatusYes}")
    Integer findTodayVisitsNumber(LocalDate now, String orderstatusYes);

    /**
     * 本周预约数
     * @param thisWeekMonday
     * @return
     */
    @Select("select count(*) from t_order where orderDate >= date (#{thisWeekMonday})")
    Integer findThisWeekOrderNumber(Date thisWeekMonday);

    /**
     * 本周到诊数
     * @param thisWeekMonday
     * @param orderstatusYes
     * @return
     */
    @Select("select count(*) from t_order where orderDate >= date (#{thisWeekMonday}) and orderStatus = #{orderstatusYes}")
    Integer findThisWeekVisitsNumber(Date thisWeekMonday, String orderstatusYes);

    /**
     * 本月预约数
     * @param firstDay4ThisMonth
     * @return
     */
    @Select("select count(*) from t_order where orderDate >= date (#{firstDay4ThisMonth})")
    Integer findThisMonthOrderNumber(Date firstDay4ThisMonth);

    /**
     * 本月到诊数
     * @param firstDay4ThisMonth
     * @param orderstatusYes
     * @return
     */
    @Select("select count(*) from t_order where orderDate >= date (#{firstDay4ThisMonth}) and orderStatus = #{orderstatusYes}")
    Integer findThisMonthVisitsNumber(Date firstDay4ThisMonth, String orderstatusYes);
}
